/****************************************************************************** ** Functions by Derrick Sobodash ** http://www.cinnamonpirate.com/ ** Submitted to ROM Hacking.net on July 3, 2006 ******************************************************************************/ /****************************************************************************** ** hi2lorom() ******************************************************************************* ** syntax: int hi2lorom(int value) ******************************************************************************* ** Converts a hirom SNES offset to a lorom value and returns the result as ** an integer. ******************************************************************************* ** Example: echo "HiROM:0x12f90 -- LoROM:0x" . dechex(hi2lorom(0x12f90)); ** Return : HiROM:0x12f90 -- LoROM:0x2af90 ******************************************************************************/ function hi2lorom($value) { if($value > 0xffffff) die("Error: hi2lorom(): Cannot accept values greater than 24-bits\n\n"); $value = ((int) ($value / 0x10000)) * 2 * 0x10000 + ($value % 0x10000); if(($value % 0x10000) > 0x8000) $value += 0x10000; else $value += 0x8000; return(((int) ($value / 0x10000) * 0x10000) + ($value % 0x10000)); } /****************************************************************************** ** lo2hirom() ******************************************************************************* ** syntax: int lo2hirom(int value) ******************************************************************************* ** Converts a lorom SNES offset to a hirom value and returns the result as ** an integer. ******************************************************************************* ** Example: echo "HiROM:0x" . dechex(lo2hirom(0xb9f90)) . " -- LoROM:0xb9f90"; ** Return : HiROM:0x59f90 -- LoROM:0xb9f90 ******************************************************************************/ function lo2hirom($value) { if($value > 0xffffff) die("Error: lo2hirom(): Cannot accept values greater than 24-bits\n\n"); // We need to cast this calue to int type, otherwise we will get // a floating point number if((int) ($value / 0x10000) % 2 != 0) $value -= 0x10000; else $value -= 0x8000; return((int) ($value / 0x10000) * 0x8000 + ($value % 0x10000)); }